home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 1991 Aladdin Enterprises. All rights reserved.
- Distributed by Free Software Foundation, Inc.
-
- This file is part of Ghostscript.
-
- Ghostscript is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
- to anyone for the consequences of using it or for whether it serves any
- particular purpose or works at all, unless he says so in writing. Refer
- to the Ghostscript General Public License for full details.
-
- Everyone is granted permission to copy, modify and redistribute
- Ghostscript, but only under the conditions described in the Ghostscript
- General Public License. A copy of this license is supposed to have been
- given to you along with Ghostscript so you can know your rights and
- responsibilities. It should be in a file named COPYING. Among other
- things, the copyright notice and this notice must be preserved on all
- copies. */
-
- /* gdevvdi.c */
-
- /* Bitmapped screen device for the Atari ST. This driver contains
- * portions of code originally written by Hauke Hess. This device
- * uses the vdi for all screen operations. It recognizes and supports
- * 1, 2, 4, and 8 bit color. Tim Gallivan 10/92.
- */
-
- /* For monochrome, Ghostscript produces a bitmap in memory which
- * is referenced directly by 'base'. For color images, GS produces
- * a bitmap at 'base' with each byte representing one pixel,
- * regardless of how many bits the ST actually uses. The routine
- * 'pack_to_plane()' copies the GS "packed" image format into the
- * appropriate number of color planes, referenced by 'cbase'. The
- * image in 'cbase' is then copied back to 'base' with the vdi routine
- * 'vr_trnfm()', and is then copied to the screen. This is rather
- * convoluted, but is needed for portability.
- */
-
- #include <stdio.h>
- #include <osbind.h>
- #include <gemdefs.h>
- #include <aesbind.h>
- #include <vdibind.h>
- #include <string.h>
- #include <stdlib.h>
- #include "gdevprn.h"
- #include <math.h>
-
- /* Define the default device parameters. */
-
- #ifndef X_DPI
- #define X_DPI 80
- #endif
- #ifndef Y_DPI
- #define Y_DPI 80
- #endif
-
- #define UL (unsigned long)
- #define WIDTH_10THS 85
- #define HEIGHT_10THS 110
-
- #define MIN(x, y) ((x <= y) ? x : y)
- #define MAX(x, y) ((x >= y) ? x : y)
-
- /* Macros for casting the pdev argument */
-
- #define ppdev ((gx_device_printer *)pdev)
- #define pmemdev ((gx_device_memory *)pdev)
-
- #define W_FEATURES (NAME+CLOSER+MOVER+SIZER+FULLER+VSLIDE\
- +HSLIDE+UPARROW+DNARROW+LFARROW+RTARROW)
- #define ABOUT 11
- #define NEXT 20
- #define QUIT 21
-
- /* Menu bar when windows are enabled. */
-
- OBJECT menu[] = {
-
- /* 0 */ {-1, 1, 9, G_IBOX, 0, 0, 0L, 0, 0, 80, 25},
- /* 1 */ { 9, 2, 2, G_BOX , 0, 0, 0x1100L, 0, 0, 80, 513},
-
- /* 2 */ { 1, 3, 4, G_IBOX, 0, 0, 0L, 2, 0, 15, 769},
- /* 3 */ { 4, -1, -1, G_TITLE, 0, 0, UL" Desk ", 0, 0, 6, 769},
- /* 4 */ { 2, -1, -1, G_TITLE, 0, 0, UL" Display ", 6, 0, 9, 769},
- /* 5 */ { 6, -1, -1, G_TITLE, 0, DISABLED, UL"", 15, 0, 10, 769},
- /* 6 */ { 7, -1, -1, G_TITLE, 0, DISABLED, UL"", 25, 0, 10, 769},
- /* 7 */ { 8, -1, -1, G_TITLE, 0, DISABLED, UL"", 35, 0, 10, 769},
- /* 8 */ { 2, -1, -1, G_TITLE, 0, DISABLED, UL"", 45, 0, 10, 769},
-
- /* 9 */ { 0, 10, 19, G_IBOX, 0, 0, 0L, 0, 769, 80, 19},
-
- /* 10 */ { 19, 11, 18, G_BOX , 0, 0, 0xff1100L, 2, 0, 20, 8},
- /* 11 */ { 12, -1, -1, G_STRING , 0, 0, UL" About stvdi", 0, 0, 20, 1},
- /* 12 */ { 13, -1, -1, G_STRING , 0, 0x08, UL" ------------------ ", 0, 1, 20, 1},
- /* 13 */ { 14, -1, -1, G_STRING , 0, 0, UL"1", 0, 2, 20, 1},
- /* 14 */ { 15, -1, -1, G_STRING , 0, 0, UL"2", 0, 3, 20, 1},
- /* 15 */ { 16, -1, -1, G_STRING , 0, 0, UL"3", 0, 4, 20, 1},
- /* 16 */ { 17, -1, -1, G_STRING , 0, 0, UL"4", 0, 5, 20, 1},
- /* 17 */ { 18, -1, -1, G_STRING , 0, 0, UL"5", 0, 6, 20, 1},
- /* 18 */ { 10, -1, -1, G_STRING , 0, 0, UL"6", 0, 7, 20, 1},
-
- /* 19 */ { 9, 20, 21, G_BOX , 0, 0, 0xff1100L, 8, 0, 14, 2},
- /* 20 */ { 21, -1, -1, G_STRING , 0, 0, UL" Next Page n", 0, 0, 14, 1},
- /* 21 */ { 19, -1, -1, G_STRING , 0, 0, UL" Quit q", 0, 1, 14, 1},
- /* 22 */ { 23, -1, -1, G_STRING , 0, DISABLED, UL"", 0, 2, 14, 1},
- /* 23 */ { 24, -1, -1, G_STRING , 0, DISABLED, UL"", 0, 3, 14, 1},
- /* 24 */ { 25, -1, -1, G_STRING , 0, DISABLED, UL"", 0, 4, 14, 1},
- /* 25 */ { 19, -1, -1, G_STRING , LASTOB, DISABLED, UL"", 0, 5, 14, 1}
-
- };
-
- /* About stvdi dialog object. */
-
- OBJECT about[] = {
- /* 0 */ {-1, 1, 10, G_BOX, 0, 16, 0x00021100L, 0, 0, 29, 15},
- /* 1 */ { 2, -1, -1, G_STRING, 0, 0, UL"Ghostscript Screen Driver", 2, 1, 25, 1},
- /* 2 */ { 3, -1, -1, G_STRING, 0, 0, UL"For The Atari ST", 6, 2, 16, 1},
- /* 3 */ { 4, -1, -1, G_STRING, 0, 0, UL"Tim Gallivan, 1992", 5, 3, 18, 1},
- /* 4 */ { 5, -1, -1, G_STRING, 0, 0, UL"n: Next Page", 5, 5, 13, 1},
- /* 5 */ { 6, -1, -1, G_STRING, 0, 0, UL"q: Quit Ghostscript", 5, 6, 20, 1},
- /* 6 */ { 7, -1, -1, G_STRING, 0, 0, UL"\001\002: Page Up/Down", 5, 7, 16, 1},
- /* 7 */ { 8, -1, -1, G_STRING, 0, 0, UL"\004\003: Page Left/Right", 5, 8, 19, 1},
- /* 8 */ { 9, -1, -1, G_STRING, 0, 0, UL"Scroll Bar Arrows", 6, 10, 17, 1},
- /* 9 */ {10, -1, -1, G_STRING, 0, 0, UL"Move to Page Edges.", 5, 11, 19, 1},
- /* 10 */ { 0, -1, -1, G_BUTTON, 0x62, 0, UL" OK ", 10, 13, 8, 1}
- };
-
- /* General screen driver variables. */
-
- /* lineptr is an array of pointers to the beginning of each scan line
- * in the GS bitmap.
- */
-
- byte *cbase, **lineptr, *palette;
- uint csize, palette_size;
-
- int wchar, hchar, wbox, hbox;
- int x_res, y_res, color_bits;
- int width, height, byte_width, word_width, raster;
- int plot_x, plot_y, step_dx, step_dy;
- int copy_width, copy_height;
-
- /* Variables needed for GEM windows. */
-
- char *title = " Ghostscript ";
- int msgbuff[8], pxy[8];
- int gem_handle, vdi_handle, win_handle=0, win_opened=0;
- int wait_event, button_state, mx, my, mb, mk, key, clicks;
- int hslide_pos, hslide_siz, vslide_pos, vslide_siz;
- int menuitem=0, scrollitem=0;
- int window=0, event, exit_obj;
- int cx, cy, cw, ch;
-
- GRECT canvas, frame, oldframe, maxframe, full;
- MFDB plane_image, image, screen;
-
- /* Global Ghostscript variables. */
-
- gx_color_value max_rgb;
- ulong mem_space;
-
- private dev_proc_open_device(stvdi_open);
- private dev_proc_close_device(stvdi_close);
- private dev_proc_output_page(stvdi_output_page);
- private dev_proc_print_page(stvdi_print_page);
- private dev_proc_map_rgb_color(stvdi_map_rgb_color);
- private dev_proc_map_color_rgb(stvdi_map_color_rgb);
-
- private gx_device_procs stvdi_procs =
- prn_color_procs(stvdi_open, stvdi_output_page, stvdi_close,
- stvdi_map_rgb_color, stvdi_map_color_rgb);
-
- gx_device_printer gs_stvdi_device =
- prn_device(stvdi_procs, "stvdi",
- WIDTH_10THS, HEIGHT_10THS,
- X_DPI, Y_DPI,
- 0,0,0,0, /* margins */
- 1, stvdi_print_page); /* default to monochrome */
-
- /* Open the stvdi device--get the resolution, allocate memory, etc. */
-
- int
- stvdi_open(gx_device *pdev)
- {
- const gx_device_memory *mdev;
- gx_device_procs *pprocs = pdev->procs;
-
- byte *base;
- char *env;
-
- int work_out[57], rgb[3], color_index[256];
- int work_in[11] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2};
- int i, j, ret;
-
- float aspect_ratio;
-
- /* Check the GS_WIN environment variable to decide what to
- * do about windows. "Batch" means that GS can assume no
- * user I/O will take place. "Interact" mode is for interactive
- * use.
- */
-
- if ((env = getenv("GS_WIN")) != NULL) {
- if (!strcmp(env, "batch")) {
- window = 1;
- }
- else if (!strcmp(env, "interact")) {
- window = 2;
- }
- }
-
- /* Call appl_init() to initialize the aes before using any aes
- * functions.
- */
-
- if (appl_init() == -1) {
- eprintf("stvdi_open: appl_init() failed!\n");
- return -1;
- }
-
- /* Open a virtual workstation and get the screen resolution. */
-
- gem_handle = graf_handle(&wchar, &hchar, &wbox, &hbox);
- vdi_handle = gem_handle;
- v_opnvwk(work_in, &vdi_handle, work_out);
-
- if (vdi_handle == 0) {
- eprintf("stvdi_open: Could not open virtual screen workstation");
- exit(-1);
- }
-
- x_res = work_out[0];
- y_res = work_out[1];
-
- palette_size = 3 * work_out[13];
- max_rgb = (int)(pow((float)work_out[39], .333) - .5);
- aspect_ratio = (float)(work_out[3])/(float)(work_out[4]);
-
- /* Adjust the y resolution to compensate for the aspect ratio. */
-
- pdev->y_pixels_per_inch =
- (int)(aspect_ratio * pdev->y_pixels_per_inch + .5);
- pdev->height = (int)(aspect_ratio * pdev->height + .5);
-
- /* Get the number of color planes. */
-
- vq_extnd(vdi_handle, 1, work_out);
-
- #ifdef 8BIT
- color_bits = 8;
- #else
- color_bits = work_out[4];
- #endif
-
- if (color_bits != 1 && color_bits != 2 &&
- color_bits != 4 && color_bits != 8) {
- eprintf1("stvdi_open: %d bit color is not supported.\n", color_bits);
- return -1;
- }
-
- /* Get an appropriate memory device. For the moment, this must
- * be an 8-bit device for color images.
- */
-
- if ((mdev = gdev_mem_device_for_bits(color_bits > 1 ? 8 : 1)) == 0)
- return_error(gs_error_rangecheck);
-
- width = pmemdev->width;
- height = pmemdev->height;
-
- byte_width = (width + 7) >> 3;
- word_width = (byte_width + 1) >> 1;
-
- /* Fill the color_info structure. */
-
- if (color_bits > 1) {
- int psize = palette_size/3;
-
- /* Fill the array color_index. The value of color_index[i]
- * will be the vdi color_index which corresponds to the
- * ith hardware color register.
- */
-
- #ifndef 8BIT
- reg_to_index(color_index, color_bits, psize);
- #endif
- /* Fill the color_info structure. */
-
- ppdev->color_info.num_components = mdev->color_info.num_components;
- ppdev->color_info.depth = mdev->color_info.depth;
- ppdev->color_info.max_gray = color_bits >= 8 ? 255 : 1;
- ppdev->color_info.max_rgb = max_rgb;
- ppdev->color_info.dither_gray = color_bits >= 8 ? 5 : 2;
- ppdev->color_info.dither_rgb = color_bits >= 8 ? 5 : 2;
- }
-
- memset(ppdev->skip, 0, sizeof(ppdev->skip));
- ppdev->orig_procs = pprocs;
- ppdev->page_count = 0;
- ppdev->file = ppdev->ccfile = ppdev->cbfile = NULL;
- mem_space = gdev_mem_bitmap_size(pmemdev);
-
- if (color_bits > 1) {
- csize = (uint)(2 * word_width * height * color_bits);
- mem_space = MAX(mem_space, csize);
- }
-
- /* Base points to a buffer that GS uses to construct the image. */
-
- if ( mem_space != (uint)mem_space || /* too big to allocate */
- (base = (byte *)gs_malloc((uint)mem_space, 1, "printer buffer"))
- == 0 /* can't allocate */
- ) {
- eprintf("stvdi_open: Malloc for printer buffer failed.\n");
- return_error(gs_error_VMerror);
- }
-
- /* Cbase points to a buffer that holds the standard GEM
- * color plane image.
- */
-
- if (color_bits > 1) {
- if ((cbase = (byte *)gs_malloc(csize, 1, "color buffer")) == 0) {
- eprintf("stvdi_open: Malloc for color buffer failed.\n");
- return_error(gs_error_VMerror);
- }
- }
-
- /* Render entirely in memory. */
-
- ppdev->buffer_space = 0;
- ppdev->ccfile = NULL;
- ppdev->cbfile = NULL;
- pmemdev->base = base;
- ppdev->mod_procs = *mdev->procs;
-
- /* Synthesize the procedure vector. */
- /* Rendering operations come from the memory device, */
- /* non-rendering come from the printer device. */
-
- pdev->procs = &ppdev->mod_procs;
- #define copy_proc(p) ppdev->mod_procs.p = pprocs->p
- copy_proc(get_initial_matrix);
- copy_proc(output_page);
- copy_proc(close_device);
- copy_proc(map_rgb_color);
- copy_proc(map_color_rgb);
- copy_proc(get_props);
- copy_proc(put_props);
- #undef copy_proc
-
- /* Initialize the memory device. */
-
- if ((ret = (*pdev->procs->open_device)(pdev)) != 0) {
- return ret;
- }
-
- raster = pmemdev->raster;
-
- if (color_bits > 1) {
-
- /* Set up the palette. */
-
- pmemdev->palette_size = palette_size;
-
- if ((palette = (byte *)gs_malloc((uint)palette_size, 1, "palette"))
- == NULL) {
- eprintf("stvdi_open: No memory for color palette!\n");
- return_error(gs_error_VMerror);
- }
-
- #ifdef 8BIT
- palette[0] = 0;
- palette[1] = 0;
- palette[2] = 0;
-
- for (i=3; i<palette_size; i++) {
- palette[i] = 1;
- }
- #else
- for (i=0, j=0; j<palette_size; i++, j+=3) {
- vq_color(vdi_handle, color_index[i], 0, rgb);
- palette[j] = (max_rgb * rgb[0])/937;
- palette[j+1] = (max_rgb * rgb[1])/937;
- palette[j+2] = (max_rgb * rgb[2])/937;
- }
- #endif
- pmemdev->palette = palette;
-
- }
-
- /* Window initialization. */
-
- if (window) {
- wind_get(0, WF_WORKXYWH, &full.g_x, &full.g_y,
- &full.g_w, &full.g_h);
-
- win_handle = wind_create(W_FEATURES, full.g_x, full.g_y,
- full.g_w, full.g_h);
- if (win_handle == -1) {
- form_alert(1,
- "[3][Fatal Error !|Window not available.][Abort]");
- return -1;
- }
-
- /* Fix object sizes for current resolution. */
-
- objc_fix(menu);
- objc_fix(about);
-
- wind_set(win_handle, WF_NAME, title, title, 0, 0);
-
- wind_get(win_handle, WF_WORKXYWH, &canvas.g_x, &canvas.g_y,
- &canvas.g_w, &canvas.g_h);
-
- wind_calc(0, W_FEATURES, canvas.g_x, canvas.g_y, width, height,
- &maxframe.g_x, &maxframe.g_y,
- &maxframe.g_w, &maxframe.g_h);
-
- }
-
- /* Set up the MFDBs for the images and the screen. */
-
- screen.fd_addr = (long)NULL;
-
- image.fd_addr = (long)base;
- image.fd_w = (color_bits > 1) ? 16 * word_width : 8 * raster;
- image.fd_h = height;
- image.fd_wdwidth = image.fd_w/16;
- image.fd_stand = 0;
- image.fd_nplanes = color_bits;
-
- if (color_bits > 1) {
- plane_image.fd_addr = (long)cbase;
- plane_image.fd_w = 16 * word_width;
- plane_image.fd_h = height;
- plane_image.fd_wdwidth = image.fd_w/16;
- plane_image.fd_stand = 1;
- plane_image.fd_nplanes = color_bits;
- }
-
- return 0;
- }
-
- /* Close the stvdi device--free memory, close workstations, etc. */
- int
- stvdi_close(gx_device *pdev)
- {
- /* Free the memory device bitmap */
-
- gs_free((char *)pmemdev->base, (uint)gdev_mem_bitmap_size(pmemdev),
- 1, "printer buffer");
-
- /* Free the memory for the color image buffer and palette. */
-
- if (color_bits > 1) {
- gs_free((char *)cbase, csize, 1, "color buffer");
- gs_free((char *)palette, palette_size, 1, "palette");
- }
-
- /* Free the resources used by the aes. */
-
- menu_bar(menu, 0);
- graf_mouse(ARROW, 0L);
-
- if (window) {
- wind_delete(win_handle);
- }
-
- v_clsvwk(vdi_handle);
- if (appl_exit() == 0) {
- eprintf("stvdi_close: appl_exit() failed!\n");
- return -1;
- }
-
- pdev->procs = ppdev->orig_procs;
-
- return 0;
- }
-
- int
- stvdi_output_page(gx_device *pdev, int num_copies, int flush)
- { int code;
-
- ppdev->page_count++;
-
- /* print the accumulated page description */
- code = (*ppdev->print_page)(ppdev, ppdev->file);
- if ( code < 0 ) return code;
-
- return 0;
- }
-
- /* Print the bitmap for the current page to the screen. */
-
- private int
- stvdi_print_page(gx_device_printer *pdev, FILE *dummy)
- {
- byte *base;
-
- int count, show_end, pad;
-
- long ch;
-
- /* Switch to graphics mode / clear the screen. */
-
- switch (window) {
-
- case 0:
- case 2:
- v_exit_cur(vdi_handle);
- break;
-
- default:
- break;
-
- }
-
- /* Open a window if requested */
-
- if (window && !win_opened) {
-
- restore_bg();
- graf_mouse(M_OFF, 0L );
-
- menu_bar(menu, 1);
-
- wind_open(win_handle, full.g_x, full.g_y,
- MIN(maxframe.g_w, full.g_w),
- MIN(maxframe.g_h, full.g_h));
-
- wind_get(win_handle, WF_CURRXYWH, &oldframe.g_x, &oldframe.g_y,
- &oldframe.g_w, &oldframe.g_h);
-
- wind_get(win_handle, WF_WORKXYWH, &canvas.g_x, &canvas.g_y,
- &canvas.g_w, &canvas.g_h);
-
- clear_win(&canvas);
- win_opened = 1;
-
- graf_mouse(BUSY_BEE, 0L);
- graf_mouse(M_ON, 0L);
-
- } else {
- copy_width = MIN(x_res, width-1); /* in pixels */
- copy_height = MIN(y_res, height-1); /* in pixels */
- step_dx = .9 * copy_width;
- step_dy = .9 * copy_height;
- }
-
- show_end = 0;
- pad = 8 * byte_width - width; /* pad bits at end of scan line */
-
- plot_x = 0;
- plot_y = 0;
-
- lineptr = pmemdev->line_ptrs;
- base = *lineptr;
-
- /* Find the first line containing nonzero bits. */
-
- while (plot_y < height) {
- /* Search the scanline for a nonzero bit. */
-
- for (count=0; (count < byte_width)
- && (base[count] == 0); ++count) ;
-
- if (count >= byte_width) { /* Empty line, continue. */
- plot_y++;
- base = lineptr[plot_y];
- }
- else if ((count==byte_width-1) && (base[count]>>pad == 0)) {
- plot_y++; /* nonzero bits in padding, continue */
- base = lineptr[plot_y];
- }
- else { /* Nonzero bits found, break loop. */
- plot_y--;
- break;
- }
- }
-
- if (plot_y < 0)
- plot_y = 0;
-
- if (plot_y >= height - copy_height)
- plot_y = (height - 1) - copy_height;
-
- /* Zero the memory to hold the plane image, convert the packed
- * image to planes, then convert the plane image to the final
- * screen format.
- */
-
- if (color_bits > 1) {
- memset(cbase, 0, csize);
- stvdi_pack_to_plane(pdev);
- vr_trnfm(vdi_handle, &plane_image, &image);
- }
-
- #ifdef 8BIT
- getchar(); return 0;
- #endif
-
- /* Copy the appropriate portion of the image to the screen. */
-
- if (window) {
- wait_event = MU_MESAG | MU_KEYBD;
- button_state = 1;
- update_scroll();
- }
-
- while (!show_end && window) {
-
- step_dx = .9 * canvas.g_w;
- step_dy = .9 * canvas.g_h;
-
- if (menuitem) { /* fake menu events for hot keys */
- event = MU_MESAG;
- msgbuff[0] = MN_SELECTED;
- msgbuff[4] = menuitem;
- menuitem = 0;
- }
- else if (scrollitem) {
- event = MU_MESAG;
- msgbuff[0] = WM_ARROWED;
- msgbuff[4] = scrollitem - 1;
- scrollitem = 0;
- }
- else {
- event = evnt_multi(wait_event, 2, 2, button_state,
- 1, mx, my, 1, 1, 0, 0, 0, 0, 0,
- msgbuff, 0L, &mx, &my, &mb, &mk,
- &key, &clicks);
- }
-
- if (event & MU_KEYBD) { /* hot keys */
-
- switch (key) {
-
- case 0x3100: /* alt-n */
- menuitem = NEXT;
- break;
-
- case 0x1000: /* alt-q */
- menuitem = QUIT;
- break;
-
- case 0x4800: /* up arrow */
- scrollitem = WA_UPPAGE + 1;
- break;
-
- case 0x5000: /* down arrow */
- scrollitem = WA_DNPAGE + 1;
- break;
-
- case 0x4b00: /* left arrow */
- scrollitem = WA_LFPAGE + 1;
- break;
-
- case 0x4d00: /* right arrow */
- scrollitem = WA_RTPAGE + 1;
- break;
-
- }
-
- }
-
- if (event & MU_MESAG) {
-
- switch (msgbuff[0]) {
-
- case MN_SELECTED:
-
- if (msgbuff[3] != -1) {
- menu_tnormal(menu, msgbuff[3], 1);
- }
-
- switch (msgbuff[4]) {
-
- case ABOUT:
- exit_obj = dialog(about);
- break;
-
- case NEXT:
- wind_close(win_handle);
- win_opened = 0;
- graf_mouse(BUSY_BEE, 0L);
- if (window == 2) {
- v_enter_cur(vdi_handle);
- }
- show_end = 1;
- break;
-
- case QUIT:
- wind_close(win_handle);
- win_opened = 0;
- if (window == 2) {
- v_enter_cur(vdi_handle);
- }
- stvdi_close((gx_device *)pdev);
- exit(0);
-
- }
-
- break;
-
- case WM_REDRAW:
- stvdi_win_redraw(0);
- break;
-
- case WM_ARROWED:
-
- switch (msgbuff[4]) {
-
- case WA_UPLINE: /* top of page */
- plot_y = 0;
- break;
-
- case WA_DNLINE: /* bottom of page */
- plot_y = (height-1) - canvas.g_h;
- break;
-
- case WA_LFLINE:
- plot_x = 0;
- break;
-
- case WA_RTLINE:
- plot_x = (width-1) - canvas.g_w;
- break;
-
- case WA_UPPAGE:
- plot_y = MAX(plot_y - step_dy, 0);
- break;
-
- case WA_DNPAGE:
- plot_y = plot_y + step_dy;
- break;
-
- case WA_LFPAGE:
- plot_x = MAX(plot_x - step_dx, 0);
- break;
-
- case WA_RTPAGE:
- plot_x = plot_x + step_dx;
- break;
-
-
- }
- update_scroll();
- stvdi_win_redraw(1);
- break;
-
- case WM_HSLID:
- plot_x = (width - canvas.g_w) * msgbuff[4]/1000;
- update_scroll();
- stvdi_win_redraw(1);
- break;
-
- case WM_VSLID:
- plot_y = (height - canvas.g_h) * msgbuff[4]/1000;
- update_scroll();
- stvdi_win_redraw(1);
- break;
-
- case WM_TOPPED:
- wind_set(win_handle, WF_TOP, 0, 0, 0, 0);
- break;
-
- case WM_CLOSED:
- wind_close(win_handle);
- win_opened = 0;
- graf_mouse(BUSY_BEE, 0L);
- if (window == 2) {
- v_enter_cur(vdi_handle);
- }
- show_end = 1;
- break;
-
- case WM_FULLED:
- wind_get(win_handle, WF_CURRXYWH,
- &frame.g_x, &frame.g_y,
- &frame.g_w, &frame.g_h);
-
- if (frame.g_x == full.g_x &&
- frame.g_y == full.g_y &&
- frame.g_w == MIN(maxframe.g_w, full.g_w) &&
- frame.g_h == MIN(maxframe.g_h, full.g_h)) {
-
- wind_set(win_handle, WF_CURRXYWH,
- oldframe.g_x, oldframe.g_y,
- oldframe.g_w, oldframe.g_h);
-
- wind_get(win_handle, WF_WORKXYWH,
- &canvas.g_x, &canvas.g_y,
- &canvas.g_w, &canvas.g_h);
-
- }
- else {
- oldframe.g_x = frame.g_x;
- oldframe.g_y = frame.g_y;
- oldframe.g_w = frame.g_w;
- oldframe.g_h = frame.g_h;
-
- wind_set(win_handle, WF_CURRXYWH,
- full.g_x, full.g_y,
- MIN(maxframe.g_w, full.g_w),
- MIN(maxframe.g_h, full.g_h));
-
- wind_get(win_handle, WF_WORKXYWH,
- &canvas.g_x, &canvas.g_y,
- &canvas.g_w, &canvas.g_h);
-
- }
-
- update_scroll();
- break;
-
- case WM_MOVED:
- wind_set(win_handle, WF_CURRXYWH, msgbuff[4], msgbuff[5],
- MIN(maxframe.g_w, msgbuff[6]),
- MIN(maxframe.g_h, msgbuff[7]));
-
- wind_get(win_handle, WF_WORKXYWH,
- &canvas.g_x, &canvas.g_y,
- &canvas.g_w, &canvas.g_h);
- break;
-
- case WM_SIZED:
- wind_set(win_handle, WF_CURRXYWH, msgbuff[4], msgbuff[5],
- MIN(maxframe.g_w, msgbuff[6]),
- MIN(maxframe.g_h, msgbuff[7]));
-
- wind_get(win_handle, WF_WORKXYWH,
- &canvas.g_x, &canvas.g_y,
- &canvas.g_w, &canvas.g_h);
-
- update_scroll();
- break;
-
- }
-
- }
-
- }
-
- while (!show_end && !window) {
-
- pxy[0] = plot_x;
- pxy[1] = plot_y;
- pxy[2] = pxy[0] + copy_width;
- pxy[3] = pxy[1] + copy_height;
- pxy[4] = 0;
- pxy[5] = 0;
- pxy[6] = pxy[4] + copy_width;
- pxy[7] = pxy[5] + copy_height;
-
- graf_mouse(M_OFF, 0L );
- vs_clip(vdi_handle, 1, &pxy[4]);
- /* wind_update(BEG_UPDATE); /* lock the screen */
-
- vro_cpyfm(vdi_handle, 3, pxy, &image, &screen);
-
- /* wind_update(END_UPDATE); /* release screen */
- vs_clip(vdi_handle, 0, &pxy[4]);
- graf_mouse(ARROW, 0L );
- graf_mouse(M_ON, 0L );
-
- /* Accept keyboard commands to manipulate the screen image. */
-
- ch = (Bconin(2) >> 16) & 255; /* Get key scancode */
-
- switch(ch) {
-
- case 16: /* Q */
- show_end = 1;
- break;
-
- case 71: /* Clr/Home */
- step_dx /= 2; step_dy /= 2;
- if (step_dx < 2) step_dx = 1;
- if (step_dy < 2) step_dy = 1;
- break;
-
- case 72: /* Up cursor */
- plot_y = MAX(plot_y - step_dy, 0);
- break;
-
- case 75: /* Left cursor */
- plot_x = MAX(plot_x - step_dx, 0);
- break;
-
- case 77: /* Right cursor */
- plot_x = plot_x + step_dx;
- if (plot_x >= width - copy_width)
- plot_x = (width - 1) - copy_width;
- if (plot_x < 0) plot_x = 0;
- break;
-
- case 80: /* Down cursor */
- plot_y = plot_y + step_dy;
- if (plot_y >= height - copy_height)
- plot_y = (height - 1) - copy_height;
- if (plot_y < 0) plot_y = 0;
- break;
-
- case 82: /* Insert */
- step_dx *= 2; step_dy *= 2;
- if (step_dx > copy_width) step_dx = copy_width;
- if (step_dy > copy_height) step_dy = copy_height;
- break;
-
- case 97: /* Undo */
- plot_x = 0;
- plot_y = 0;
- break;
-
- case 98: /* Help */
- stvdi_DisplayHelp();
- Bconin(2);
- stvdi_clear_screen(0);
- break;
-
- }
-
- }
-
- switch (window) {
-
- case 0:
- case 2:
- v_enter_cur(vdi_handle);
- break;
-
- default:
- break;
-
- }
-
- return (0);
-
- }
-
- int stvdi_win_redraw(int flag)
- {
- GRECT redraw, rect;
-
- if (flag) {
- redraw.g_x = canvas.g_x;
- redraw.g_y = canvas.g_y;
- redraw.g_w = canvas.g_w;
- redraw.g_h = canvas.g_h;
- }
- else {
- redraw.g_x = msgbuff[4];
- redraw.g_y = msgbuff[5];
- redraw.g_w = msgbuff[6];
- redraw.g_h = msgbuff[7];
- }
-
- if (plot_x >= width - canvas.g_w)
- plot_x = (width - 1) - canvas.g_w;
- if (plot_x < 0) plot_x = 0;
-
- if (plot_y >= height - canvas.g_h)
- plot_y = (height - 1) - canvas.g_h;
- if (plot_y < 0) plot_y = 0;
-
- graf_mouse(M_OFF, 0L );
- /* wind_update(BEG_UPDATE); /* lock the screen */
-
- wind_get(win_handle, WF_FIRSTXYWH, &rect.g_x, &rect.g_y,
- &rect.g_w, &rect.g_h);
-
- while (rect.g_w && rect.g_h) {
- if (intersect(&redraw, &rect)) {
- if (intersect(&canvas, &rect)) {
-
- pxy[0] = plot_x + (rect.g_x - canvas.g_x);
- pxy[1] = plot_y + (rect.g_y - canvas.g_y);
- pxy[2] = pxy[0] + rect.g_w - 1;
- pxy[3] = pxy[1] + rect.g_h - 1;
-
- pxy[4] = rect.g_x;
- pxy[5] = rect.g_y;
- pxy[6] = pxy[4] + rect.g_w - 1;
- pxy[7] = pxy[5] + rect.g_h - 1;
-
- vro_cpyfm(vdi_handle, 3, pxy, &image, &screen);
- }
- }
-
- wind_get(win_handle, WF_NEXTXYWH, &rect.g_x, &rect.g_y,
- &rect.g_w, &rect.g_h);
- }
-
-
- /* wind_update(END_UPDATE); /* release screen */
-
- graf_mouse(ARROW, 0L );
- graf_mouse(M_ON, 0L );
-
- }
-
- int update_scroll()
- {
- if (width != canvas.g_w) {
- hslide_pos = 1000 * plot_x/(width - canvas.g_w);
- }
- else {
- hslide_pos = 0;
- }
-
- if (height != canvas.g_h) {
- vslide_pos = 1000 * plot_y/(height - canvas.g_h);
- }
- else {
- vslide_pos = 0;
- }
-
- hslide_siz = 1000 * canvas.g_w/width;
- vslide_siz = 1000 * canvas.g_h/height;
-
- wind_set(win_handle, WF_HSLIDE, hslide_pos);
- wind_set(win_handle, WF_VSLIDE, vslide_pos);
- wind_set(win_handle, WF_HSLSIZE, hslide_siz);
- wind_set(win_handle, WF_VSLSIZE, vslide_siz);
- }
-
- int stvdi_DisplayHelp()
- {
- dprintf2("%c%c Help for GhostScript Screen Driver\n", 27, 'E');
- dprintf(" Original Code by Hauke Hess.\n\n");
- dprintf(" Q: Quit this page (to next page or GS prompt).\n");
- dprintf(" Cursor Keys: Scroll screen in direction of cursor.\n");
- dprintf(" Help: Display help screen.\n");
- dprintf(" Undo: Move to upper-left corner of page.\n");
- dprintf(" Insert: Multiply scroll incrememt by 2.\n");
- dprintf(" Clr/Home: Divide scroll increment by 2.\n");
- dprintf("\n Command line option -r<XDPI>x<YDPI> sets resolution.\n");
-
- #if 0
- dprintf("\n Helpseite des GhostScript Previewers no(c)\n");
- dprintf(" Hauke He₧ 1991\n");
- dprintf(" Cursortasten: bewegen in entsprechender Richtung\n");
- dprintf(" Undo: Zurück nach links oben auf der Seite\n");
- dprintf(" Insert: Schrittweiter vergrö₧ern\n");
- dprintf(" Clr/Home: Schrittweite verkleinern\n");
- dprintf("\n Kommandozeilenparameter -r<XDPI>x<YDPI> setzt die Auflösung\n");
- #endif
-
- dprintf("\n >> Hit any key to continue. <<");
-
- return(0);
- }
-
- int
- stvdi_clear_screen(int cursor)
- {
- if (cursor) {
- v_enter_cur(vdi_handle);
- }
- else {
- v_exit_cur(vdi_handle);
- }
- }
-
-
- /* Map a r-g-b color to a color index. */
- /* This requires searching the palette. */
-
- gx_color_index
- stvdi_map_rgb_color(gx_device *pdev, gx_color_value r, gx_color_value g,
- gx_color_value b) {
- byte br = gx_color_value_to_byte(r);
- byte bg = gx_color_value_to_byte(g);
- byte bb = gx_color_value_to_byte(b);
- register byte *pptr = pmemdev->palette;
- int cnt = pmemdev->palette_size;
- byte *which;
- int best = 256*3;
-
- if (color_bits == 1) { /* monochrome */
- return ((r | g | b) > gx_max_color_value / 2 ?
- (gx_color_index)0 : (gx_color_index)1);
- }
-
- br = (br * max_rgb)/255;
- bg = (bg * max_rgb)/255;
- bb = (bb * max_rgb)/255;
-
- while ( cnt-- > 0 )
- { register int diff = *pptr - br;
- if ( diff < 0 ) diff = -diff;
- if ( diff < best ) /* quick rejection */
- { int dg = pptr[1] - bg;
- if ( dg < 0 ) dg = -dg;
- if ( (diff += dg) < best ) /* quick rejection */
- { int db = pptr[2] - bb;
- if ( db < 0 ) db = -db;
- if ( (diff += db) < best )
- which = pptr, best = diff;
- }
- }
- pptr += 3;
- }
- return (gx_color_index)((which - pmemdev->palette) / 3);
- }
-
- /* Map a color index to a r-g-b color. */
- int
- stvdi_map_color_rgb(gx_device *pdev, gx_color_index color,
- gx_color_value prgb[3])
- {
- byte *pptr;
-
- if (color_bits == 1) { /* monochrome */
- return gdev_prn_map_color_rgb(pdev, color, prgb);
- }
-
- pptr = pmemdev->palette + (int)color * 3;
- prgb[0] = gx_color_value_from_byte(pptr[0]);
- prgb[1] = gx_color_value_from_byte(pptr[1]);
- prgb[2] = gx_color_value_from_byte(pptr[2]);
- return 0;
- }
-
- /* Copy an image from Ghostscript's format to standard color planes. */
-
- int
- stvdi_pack_to_plane(gx_device *pdev)
- {
- byte *base, *plane1, *plane2, *plane3, *plane4,
- *plane5, *plane6, *plane7, *plane8;
-
- byte *next_pl1, *next_pl2, *next_pl3, *next_pl4,
- *next_pl5, *next_pl6, *next_pl7, *next_pl8;
-
- int pixel, line, plane_size;
-
- plane_size = 2 * word_width * height;
-
- switch (color_bits) {
-
- case 2: /* Two bit color. */
-
- next_pl1 = cbase;
- next_pl2 = cbase + plane_size;
-
- for (line=0; line < height; line++) {
- base = lineptr[line];
-
- plane1 = next_pl1;
- plane2 = next_pl2;
-
- next_pl1 += 2 * word_width;
- next_pl2 += 2 * word_width;
-
- for (pixel=0; pixel < width; plane1++, plane2++, pixel+=8) {
-
- if (*base & 0x01) *plane1 |= 0x80;
- if (*base & 0x02) *plane2 |= 0x80;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x40;
- if (*base & 0x02) *plane2 |= 0x40;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x20;
- if (*base & 0x02) *plane2 |= 0x20;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x10;
- if (*base & 0x02) *plane2 |= 0x10;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x08;
- if (*base & 0x02) *plane2 |= 0x08;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x04;
- if (*base & 0x02) *plane2 |= 0x04;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x02;
- if (*base & 0x02) *plane2 |= 0x02;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x01;
- if (*base & 0x02) *plane2 |= 0x01;
- ++base;
-
- }
-
- }
-
- break;
-
- case 4: /* Four bit color. */
-
- next_pl1 = cbase;
- next_pl2 = cbase + plane_size;
- next_pl3 = cbase + 2 * plane_size;
- next_pl4 = cbase + 3 * plane_size;
-
- for (line=0; line < height; line++) {
- base = lineptr[line];
-
- plane1 = next_pl1;
- plane2 = next_pl2;
- plane3 = next_pl3;
- plane4 = next_pl4;
-
- next_pl1 += 2 * word_width;
- next_pl2 += 2 * word_width;
- next_pl3 += 2 * word_width;
- next_pl4 += 2 * word_width;
-
- for (pixel=0; pixel < width; plane1++, plane2++,
- plane3++, plane4++, pixel+=8) {
-
- if (*base & 0x01) *plane1 |= 0x80;
- if (*base & 0x02) *plane2 |= 0x80;
- if (*base & 0x04) *plane3 |= 0x80;
- if (*base & 0x08) *plane4 |= 0x80;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x40;
- if (*base & 0x02) *plane2 |= 0x40;
- if (*base & 0x04) *plane3 |= 0x40;
- if (*base & 0x08) *plane4 |= 0x40;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x20;
- if (*base & 0x02) *plane2 |= 0x20;
- if (*base & 0x04) *plane3 |= 0x20;
- if (*base & 0x08) *plane4 |= 0x20;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x10;
- if (*base & 0x02) *plane2 |= 0x10;
- if (*base & 0x04) *plane3 |= 0x10;
- if (*base & 0x08) *plane4 |= 0x10;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x08;
- if (*base & 0x02) *plane2 |= 0x08;
- if (*base & 0x04) *plane3 |= 0x08;
- if (*base & 0x08) *plane4 |= 0x08;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x04;
- if (*base & 0x02) *plane2 |= 0x04;
- if (*base & 0x04) *plane3 |= 0x04;
- if (*base & 0x08) *plane4 |= 0x04;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x02;
- if (*base & 0x02) *plane2 |= 0x02;
- if (*base & 0x04) *plane3 |= 0x02;
- if (*base & 0x08) *plane4 |= 0x02;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x01;
- if (*base & 0x02) *plane2 |= 0x01;
- if (*base & 0x04) *plane3 |= 0x01;
- if (*base & 0x08) *plane4 |= 0x01;
- ++base;
-
- }
-
- }
-
- break;
-
- case 8: /* Eight bit color. */
-
- next_pl1 = cbase;
- next_pl2 = cbase + plane_size;
- next_pl3 = cbase + 2 * plane_size;
- next_pl4 = cbase + 3 * plane_size;
- next_pl5 = cbase + 4 * plane_size;
- next_pl6 = cbase + 5 * plane_size;
- next_pl7 = cbase + 6 * plane_size;
- next_pl8 = cbase + 7 * plane_size;
-
- for (line=0; line < height; line++) {
- base = lineptr[line];
-
- plane1 = next_pl1;
- plane2 = next_pl2;
- plane3 = next_pl3;
- plane4 = next_pl4;
- plane5 = next_pl5;
- plane6 = next_pl6;
- plane7 = next_pl7;
- plane8 = next_pl8;
-
- next_pl1 += 2 * word_width;
- next_pl2 += 2 * word_width;
- next_pl3 += 2 * word_width;
- next_pl4 += 2 * word_width;
- next_pl5 += 2 * word_width;
- next_pl6 += 2 * word_width;
- next_pl7 += 2 * word_width;
- next_pl8 += 2 * word_width;
-
- for (pixel=0; pixel < width; plane1++, plane2++,
- plane3++, plane4++, plane5++, plane6++,
- plane7++, plane8++, pixel+=8) {
-
- if (*base & 0x01) *plane1 |= 0x80;
- if (*base & 0x02) *plane2 |= 0x80;
- if (*base & 0x04) *plane3 |= 0x80;
- if (*base & 0x08) *plane4 |= 0x80;
- if (*base & 0x10) *plane5 |= 0x80;
- if (*base & 0x20) *plane6 |= 0x80;
- if (*base & 0x40) *plane7 |= 0x80;
- if (*base & 0x80) *plane8 |= 0x80;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x40;
- if (*base & 0x02) *plane2 |= 0x40;
- if (*base & 0x04) *plane3 |= 0x40;
- if (*base & 0x08) *plane4 |= 0x40;
- if (*base & 0x10) *plane5 |= 0x40;
- if (*base & 0x20) *plane6 |= 0x40;
- if (*base & 0x40) *plane7 |= 0x40;
- if (*base & 0x80) *plane8 |= 0x40;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x20;
- if (*base & 0x02) *plane2 |= 0x20;
- if (*base & 0x04) *plane3 |= 0x20;
- if (*base & 0x08) *plane4 |= 0x20;
- if (*base & 0x10) *plane5 |= 0x20;
- if (*base & 0x20) *plane6 |= 0x20;
- if (*base & 0x40) *plane7 |= 0x20;
- if (*base & 0x80) *plane8 |= 0x20;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x10;
- if (*base & 0x02) *plane2 |= 0x10;
- if (*base & 0x04) *plane3 |= 0x10;
- if (*base & 0x08) *plane4 |= 0x10;
- if (*base & 0x10) *plane5 |= 0x10;
- if (*base & 0x20) *plane6 |= 0x10;
- if (*base & 0x40) *plane7 |= 0x10;
- if (*base & 0x80) *plane8 |= 0x10;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x08;
- if (*base & 0x02) *plane2 |= 0x08;
- if (*base & 0x04) *plane3 |= 0x08;
- if (*base & 0x08) *plane4 |= 0x08;
- if (*base & 0x10) *plane5 |= 0x08;
- if (*base & 0x20) *plane6 |= 0x08;
- if (*base & 0x40) *plane7 |= 0x08;
- if (*base & 0x80) *plane8 |= 0x08;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x04;
- if (*base & 0x02) *plane2 |= 0x04;
- if (*base & 0x04) *plane3 |= 0x04;
- if (*base & 0x08) *plane4 |= 0x04;
- if (*base & 0x10) *plane5 |= 0x04;
- if (*base & 0x20) *plane6 |= 0x04;
- if (*base & 0x40) *plane7 |= 0x04;
- if (*base & 0x80) *plane8 |= 0x04;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x02;
- if (*base & 0x02) *plane2 |= 0x02;
- if (*base & 0x04) *plane3 |= 0x02;
- if (*base & 0x08) *plane4 |= 0x02;
- if (*base & 0x10) *plane5 |= 0x02;
- if (*base & 0x20) *plane6 |= 0x02;
- if (*base & 0x40) *plane7 |= 0x02;
- if (*base & 0x80) *plane8 |= 0x02;
- ++base;
-
- if (*base & 0x01) *plane1 |= 0x01;
- if (*base & 0x02) *plane2 |= 0x01;
- if (*base & 0x04) *plane3 |= 0x01;
- if (*base & 0x08) *plane4 |= 0x01;
- if (*base & 0x10) *plane5 |= 0x01;
- if (*base & 0x20) *plane6 |= 0x01;
- if (*base & 0x40) *plane7 |= 0x01;
- if (*base & 0x80) *plane8 |= 0x01;
- ++base;
-
- }
-
- }
-
- break;
-
- default:
- return -1;
-
- }
-
- return (0);
- }
-
- int dialog(OBJECT *object)
- {
- int exit_but;
-
- form_center(object, &cx, &cy, &cw, &ch);
- form_dial(FMD_START, 0, 0, wchar, hchar, cx, cy, cw, ch);
- objc_draw(object, 0, 5, cx, cy, cw, ch);
-
- exit_but = form_do(object, 0);
-
- form_dial(FMD_FINISH, 0, 0, wchar, hchar, cx, cy, cw, ch);
- objc_change(&object[exit_but], 0, 0, cx, cy, cw, ch, NORMAL, 0);
-
- return exit_but;
- }
-
- int intersect(GRECT *rec1, GRECT *rec2)
- {
- GRECT temp;
-
- temp.g_x = MAX(rec1->g_x, rec2->g_x);
- temp.g_y = MAX(rec1->g_y, rec2->g_y);
- temp.g_w = MIN(rec1->g_x + rec1->g_w, rec2->g_x + rec2->g_w);
- temp.g_h = MIN(rec1->g_y + rec1->g_h, rec2->g_y + rec2->g_h);
-
- rec2->g_x = temp.g_x;
- rec2->g_y = temp.g_y;
- rec2->g_w = temp.g_w - temp.g_x;
- rec2->g_h = temp.g_h - temp.g_y;
-
- return ((temp.g_w > temp.g_x) && (temp.g_h > temp.g_y));
- }
-
- /* Restore the usual desktop background. */
-
- int restore_bg()
- {
- puts("\033f");
- v_hide_c(vdi_handle);
- form_dial(FMD_FINISH, 0, 0, 8, 16, 0, 0, x_res, y_res);
- v_show_c(vdi_handle, 0);
- }
-
- /* Adjust the size of an object for the current screen resolution. */
-
- int objc_fix(OBJECT *object)
- {
- int i=-1;
-
- do {
- i++;
-
- if (object[i].ob_x == 769) object[i].ob_x = full.g_y;
- else if (object[i].ob_x == 513) object[i].ob_x = full.g_y;
- else object[i].ob_x *= wchar;
-
- if (object[i].ob_y == 769) object[i].ob_y = full.g_y;
- else if (object[i].ob_y == 513) object[i].ob_y = full.g_y;
- else object[i].ob_y *= hchar;
-
- if (object[i].ob_width == 769) object[i].ob_width = full.g_y;
- else if (object[i].ob_width == 513) object[i].ob_width = full.g_y;
- else if (object[i].ob_width == 80) object[i].ob_width = full.g_w;
- else object[i].ob_width *= wchar;
-
- if (object[i].ob_height == 769) object[i].ob_height = full.g_y;
- else if (object[i].ob_height == 513) object[i].ob_height = full.g_y;
- else object[i].ob_height *= hchar;
-
- }
- while (!(object[i].ob_flags & LASTOB));
-
- }
-
- int clear_win(GRECT *area)
- {
- int xy[4];
-
- xy[0] = area->g_x;
- xy[1] = area->g_y;
- xy[2] = xy[0] + area->g_w - 1;
- xy[3] = xy[1] + area->g_h - 1;
-
- vsf_interior(vdi_handle, 0); /* set fill mode to hollow */
- vr_recfl(vdi_handle, xy); /* clear the window */
- }
-
- int reg_to_index(int index_array[], int c_bits, int p_size)
- {
- unsigned short *wp;
-
- int i, index, creg, xy_pos[2], xy_size[8];
-
- long tpixel[4], plane[4];
-
- MFDB temp, screen, planes;
-
- screen.fd_addr = (long)NULL;
-
- /* Temporary storage for for 16 screen pixels. */
-
- temp.fd_addr = (long)tpixel;
- temp.fd_w = 16;
- temp.fd_h = 1;
- temp.fd_wdwidth = 1;
- temp.fd_stand = 0;
- temp.fd_nplanes = c_bits;
-
- /* 16 screen pixels in plane format. */
-
- planes.fd_addr = (long)plane;
- planes.fd_w = 16;
- planes.fd_h = 1;
- planes.fd_wdwidth = 1;
- planes.fd_stand = 0;
- planes.fd_nplanes = c_bits;
-
- /* Screen position to write pixel. */
-
- xy_pos[0] = 0;
- xy_pos[1] = 0;
-
- /* Size of screen image to copy. */
-
- xy_size[0] = 0;
- xy_size[1] = 0;
- xy_size[2] = 15;
- xy_size[3] = 0;
- xy_size[4] = xy_size[0];
- xy_size[5] = xy_size[1];
- xy_size[6] = xy_size[2];
- xy_size[7] = xy_size[3];
-
- vswr_mode(vdi_handle, 1); /* overwrite mode */
- vsm_type(vdi_handle, 1); /* marker type "dot" */
-
- for (index=0; p_size--; index++) {
- wp = (short int *)plane;
-
- vsm_color(vdi_handle, index); /* set pixel color */
- v_pmarker(vdi_handle, 1, xy_pos); /* write pixel to screen */
-
- /* Copy pixel into temporary storage (transforming directly
- * from the screen doesn't work on my machine).
- */
-
- vro_cpyfm(vdi_handle, 3, xy_size, &screen, &temp);
-
- /* Transform the screen image into color plane format. */
-
- vr_trnfm(vdi_handle, &temp, &planes);
-
- /* Convert the color plane information into a register number. */
-
- creg = 0;
- for (i=1; i<=c_bits; wp++, i++) {
- if (*wp & 0x8000) {
- creg += (1 << (i-1));
- }
- }
-
- index_array[creg] = index;
-
- }
-
- }
-